<?php
function get_goods($map,$limit,$order){
	$goods = D('Goods');

	if (is_array($map)) {
		$where = $map;
	}else{
		$map = get_category_child($map);
		$where['category_id'] = array('IN',$map);
	}
	$where['surplus'] = array('gt',0);
	$list = $goods->where($where)->order($order)->limit($limit)->select();
	return $list;
}

function get_brand_list($category){
    $list = S('sys_brand_list');
    /* 读取缓存数据 */
    if(empty($list)){
        $list = D('GoodsBrand')->select();
        S('sys_brand_list',$list);
    }
    $categorys = get_category_child($category);
    foreach ($list as $key => $value) {
        if (in_array($value['category_id'], $categorys)) {
            $res[] = $value;
        }
    }
    return $res;
}

function get_nav($Channel_id){
    for ($Channel_id;$Channel_id!=0;$Channel_id=$Channel['pid']) {
        $Channel=M('Channel')->where(array("status"=>"1","id"=>$Channel_id))->order("sort")->find();
        if($nav){
            $nav="<a href='".get_nav_url($Channel['url'],$Channel['id'])."'>".$Channel['title']."</a>->".$nav;
        }else{
            $nav="<a href='".get_nav_url($Channel['url'],$Channel['id'])."'>".$Channel['title']."</a>".$nav;
        }
    }
    return "<a href='/'>首页</a>->".$nav;
}

function sendsms($mobile,$content){
    $flag = 0; 
    $content = iconv("utf-8","gb2312//IGNORE","[南北科技]".$content);
        //要post的数据 
    $argv = array( 
         'sn'=>'SDK-JJJ-010-01435', //提供的账号
         'pwd'=>'B4339727128BAA4FDEDFC2417EF27F7D', //此处密码需要加密 加密方式为 md5(sn+password) 32位大写
         'mobile'=>$mobile,//手机号 多个用英文的逗号隔开 一次小于1000个手机号
         'content'=>urlencode($content),//多个内容分别urlencode编码然后逗号隔开
         'ext'=>'',//子号(可以空 ,可以是1个 可以是多个,多个的需要和内容和手机号一一对应)
         'stime'=>'',//定时时间 格式为2011-6-29 11:09:21
         'rrid'=>''
         ); 
    //构造要post的字符串 
    foreach ($argv as $key=>$value) { 
          if ($flag!=0) { 
             $params .= "&"; 
             $flag = 1; 
          } 
             $params.= $key."="; $params.=urlencode($value); 
             $flag = 1; 
          }
         $length = strlen($params); 
         //创建socket连接 
         $fp = fsockopen("sdk105.entinfo.cn",80,$errno,$errstr,10) or exit($errstr."--->".$errno); 
         //构造post请求的头 
         $header = "POST /webservice.asmx/gxmt HTTP/1.1\r\n"; 
         $header .= "Host:sdk105.entinfo.cn\r\n"; 
         $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
         $header .= "Content-Length: ".$length."\r\n"; 
         $header .= "Connection: Close\r\n\r\n"; 
         //添加post的字符串 
         $header .= $params."\r\n"; 
         //发送post的数据 
         fputs($fp,$header); 
         $inheader = 1; 
          while (!feof($fp)) { 
             $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据 
             if ($inheader && ($line == "\n" || $line == "\r\n")) { 
                     $inheader = 0; 
              } 
              if ($inheader == 0) { 
         // echo $line; 
              } 
          } 
          //<string xmlns="http://tempuri.org/">-5</string>
           $line=str_replace("<string xmlns=\"http://tempuri.org/\">","",$line);
           $line=str_replace("</string>","",$line);
           $result=explode("-",$line);
            if(count($result)>1)
            return '发送失败';
            else
            return '发送成功'; 

      

}
